/**
 * Project: complex.cs
 * 
 * File Created at 2010-7-1
 * $Id$
 * 
 * Copyright 2008 Alibaba.com Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Alibaba Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Alibaba.com.
 */
package com.ymkyve.eraclient.one;

import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.TimeUnit;

/**
 * @description:socket客户端
 * @author gaoliang
 * @date 2010-7-1
 * @version 1.0
 */
public class Server {
    public static void main(String[] args) {
        try {
            //建立与serverSocket的连接
            ServerSocket serverSocket = new ServerSocket(998);

            Socket socket = serverSocket.accept();
            // Socket socket = new Socket("127.0.0.1",998);

            for (int i = 0; i < 1000; i++) {

                //取得输出流
                OutputStream out = socket.getOutputStream();
                //向输出流写入内容
                out.write("test".getBytes());

                out.write("again".getBytes());
                out.close();
                TimeUnit.SECONDS.sleep(2);
            }

            //若要长连接,不关闭流和socket即可

            serverSocket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
